﻿#include "hexediter_mainwindow.h"
#include "ui_support/GlobalUiStyle.h"
#include "ui_base_lib.h"
#include <Windows.h>
#include <QScreen>
#include <QApplication>
#include <QDesktopWidget>
#include "ui_base_lib.h"
#include <QRect>

void HexEditer_MainWindow::setAppSize(int remainH)
{
    //首先获取屏幕尺寸信息
    QDesktopWidget *deskTopWidget = QApplication::desktop();
    QRect deskRect = deskTopWidget->availableGeometry();

    QScreen *screen=QGuiApplication::primaryScreen();
    QRect rect = screen->availableGeometry();
    int screenWidth = rect.width();
    int screenHeight = rect.height();

//    // 获取多显示器,通过list存储当前主机所有显示器
//    QList<QScreen *> listScreen = QGuiApplication::screens();
//    // 通过循环可以遍历每个显示器
//    int desktopWidth,desktopHeight;//屏幕分辨率
//    for (int i = 0; i < listScreen.size(); i++)
//    {
//        // 获取屏幕分辨率
//        QRect rect = listScreen.at(i)->geometry();
//        int desktopWidth = rect.width();
//        int desktopHeight = rect.height();
//    }

    setResolutionScale(screenWidth / (double)1920);
     qDebug()<<"ssss1"<<deskRect;
    //设置程序尺寸(我的界面需要适应高度)
//    int titleBarH = style()->pixelMetric(QStyle::PM_TitleBarHeight); 	// 获取标题栏高度(WIndow自带)
//    int appH = deskRect.height() - remainH/* - titleBarH*/;
//    int appW = appH*this->width() / this->height();	//根据软件的宽高比例
    int appH = 800;
    int appW = 1500;	//根据软件的宽高比例
    this->setFixedSize(appW * getResolutionScale(), appH * getResolutionScale());  		//注意：此处设置的高度是不包含标题栏
    this->setGeometry((deskRect.width() - appW * getResolutionScale()) / 2,(deskRect.height() - appH * getResolutionScale()) / 2/* + titleBarH*/, appW*getResolutionScale(), appH*getResolutionScale());	//设置程序窗体在桌面的显示位置
    qDebug()<<"ssss"<<this->size();
    setResolutionScale(1);
}


HexEditer_MainWindow::HexEditer_MainWindow(QWidget *parent):Widget(parent)
{
    this->setWindowFlags(windowFlags() | Qt::FramelessWindowHint);

//    HDC hdc = GetDC(0);
//    qreal scaleX = GetDeviceCaps(hdc, 88)/96.00;
//    qreal scaleY = GetDeviceCaps(hdc, 90)/96.00;

//    setScreenScale(scaleX);
    this->setAppSize(0);

    UI_Layout();


    /*功能界面切换绑定*/
    //connect(m_widgetTitle,&WidgetTitle::evt_pushbuttonFuncClick,this,&HexEditer_MainWindow::on_pushbuttonFuncClick);
}

void HexEditer_MainWindow::UI_Layout()
{
    /*界面默认尺寸*/
    m_DefaultWidth = 1500;
    m_DefaultHeight = 800;

    m_widgetTitle = new WidgetTitle(this);
    m_widgetTitle->move(0,0);
    m_widgetTitle->resize(1500,42);
    m_widgetTitle->setDefaultCoordinate(0,0);
    m_widgetTitle->setDefaultSize(1500,42);
    m_widgetTitle->setObjectName("Title");
    m_widgetTitle->setStyleSheet(styleWidgetGlobal);


    //设置自适应的控件
    m_widgetTitle->setAutoResize(UI_RESIZE_AUTO);
    this->addResizeBaseObj(m_widgetTitle);
}

void HexEditer_MainWindow::UI_Resize()
{
    this->addResizeBaseObj(m_widgetTitle);


    m_widgetTitle->setAutoResize(UI_RESIZE_AUTO);

}

void HexEditer_MainWindow::on_pushbuttonFuncClick()
{

}
